1. /* sdfsinrn.cpp by K.Tsuru */
  2. // function ID 3206 DRADIX
  3. /**********************************************************************************
  4. SDouble class
  5. sin x for |x| < pi/4
  6. x/(R^N) reducing method
  7. It is convenient to take R=5, because 1/(R^N) is a finite decimal fraction in
  8. DRADIX.
  9. [Algorithm]
  10. We use a formula
  11. sin(5x) = 16*sin(x)^5 - 20*sin(x)^3 + 5*sin(x).
  12. step 1 :Taking R=5 the value d = x/(R^n)(n integer) is evaluated.
  13. step 2 :We get y(n) = sin d by series.
  14. step 3 :While n > 0 we repeat
  15. y(n-1) <-- 16*y(n)^5 - 20*y(n)^3 + 5*y(n), n <-- n-1.
  16. It is better to change the value of 'n' depending the number of effective figures.
  17. **********************************************************************************/
  18. #ifndef SN_H
  19. #include "sn.h"
  20. #endif
  21. SDouble SinRN(const SDouble& x){ // |x| <= pi/4
  22. int k;
  23. const uint R = 5u;
  24. const double logR = log10((double)R); // ver. 2.17
  25. uint effFig = x.EffFig(), upPrec;
  26. double pw = log10((double)effFig);
  27. const int n = int(0.5*DFIGURES*pw*pw) + x.RdxExp();
  28. if(n <= 0) return SinSeries(x); // enough small
  29. // n > 0
  30. k = int( (double)n*logR )+ 1; //the number of figures of R^n
  31. upPrec = k/DFIGURES + 1u; //temporally raising up precision
  32. if(k % DFIGURES) upPrec++;
  33. RealSize C;
  34. SDouble u, y;
  35. uint up = x.ProperUpPrec(upPrec);
  36. //It temporally raises up the precision if possible.
  37. if(up) C.SetEffFig(effFig + up, C.TEMP_EXTEND);
  38. u = x/Dpow(R, n); // u = x/(R^n)
  39. y = SinSeries(u); //SinSeries(u); // sin(x/(5^n))
  40. k = n;
  41. x.iterationCount = n;
  42. // y(n-1) = 16*y(n)^5 - 20*y(n)^3 + 5*y(n), n <-- n-1
  43. while(k > 0){
  44. u = DsMult(y, 2); // u = 2y
  45. u *= u; // u = 4*y^2
  46. u = u*u - DsMult(u-ONE, 5); // 16*y^4 -5*(4*y^2 -1)
  47. y = u*y;
  48. k--;
  49. }
  50. if(up){
  51. C.SetEffFig(0);
  52. y.Reform(3206);
  53. }
  54. return y;
  55. }

sdfsinrn.cpp : last modifiled at 2017/09/07 15:09:42(1,844 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).